package leafedbox.managers
{
	/** 
	 * This class manages the instantation of commands as well as the management
	 * of remote addresses.
	 */
	public class CommandManager
	{
		//--------------------------------------------------------------------------
		// Static properties
		//--------------------------------------------------------------------------

		/** 
		 * The implementation.
		 */
		protected static var impl : CommandManagerImpl;


		//--------------------------------------------------------------------------
		// Static methods
		//--------------------------------------------------------------------------

		//----------------------------------
		// Singleton
		//----------------------------------

		/** 
		 * Retrieves the singleton implementation.
		 */
		public static function getInstance():CommandManagerImpl
		{
			if(!impl) {
				impl = new CommandManagerImpl();
			}
			
			return impl;
		}

		/** 
		 * Sets the singleton implementation.
		 */
		public static function setInstance(value:CommandManagerImpl):void
		{
			impl = value;
		}


		//----------------------------------
		// Remote address
		//----------------------------------

		/**
		 * Retrieves a remote address.
		 * 
		 * @param name  The lookup name of the remote address.
		 * 
		 * @return  A remote address.
		 */
		public static function getRemoteAddress(name:String="default"):String
		{
			return getInstance().getRemoteAddress(name);
		}

		/**
		 * Associates a remote address to a lookup name.
		 * 
		 * @param name  The lookup name of the remote address.
		 * @param url   The URL of the remote address.
		 */
		public static function setRemoteAddress(name:String, url:String):void
		{
			getInstance().setRemoteAddress(name, url);
		}

		/**
		 * Assigns a default remote address.
		 * 
		 * @param url   The URL of the remote address.
		 */
		public static function setDefaultRemoteAddress(url:String):void
		{
			getInstance().setDefaultRemoteAddress(url);
		}



		//----------------------------------
		// Global parameters
		//----------------------------------

		/**
		 * Retrieves a global parameter.  Global parameters are set on
		 * all commands for a given remote address.
		 * 
		 * @param name    The name of the parameter.
		 * @param method  The method to send the parameter.
		 * 
		 * @return  A value for the global parameter.
		 */
		public static function getGlobalParameter(name:String, method:String="GET"):*
		{
			return getInstance().getGlobalParameter(name, method);
		}

		/**
		 * Sets a value for a global parameter.
		 * 
		 * @param name    The name of the global parameter.
		 * @param value   The global parameter value.
		 * @param method  The method to send the parameter.
		 */
		public static function setGlobalParameter(name:String, value:*, method:String="GET"):void
		{
			getInstance().setGlobalParameter(name, value, method);
		}

		/**
		 * Retrieves the object lookup of parameters.
		 */
		public static function getGlobalParameters():Object
		{
			return getInstance().getGlobalParameters();
		}
	}

}